package com.lvwenguo.controller.echarts;

import com.google.gson.Gson;
import com.lvwenguo.model.EchartsCategory;
import com.lvwenguo.service.serviceImple.EchartsServiceImple;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/EchartsServlet")
public class EchartsServlet extends HttpServlet {
    EchartsServiceImple echartsServiceImple =new EchartsServiceImple();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<EchartsCategory> list = echartsServiceImple.TuBiao();
        Gson gson=new Gson();
        Object[] objects=new Object[8];
        Object[] objects2=new Object[8];
        Object[][] objects1=new Object[1][2];
        for(int i=0;i<list.size();i++){
            objects[i]=list.get(i).getCategory_name();
            objects2[i]=list.get(i).getSale_count();
        }
        objects1[0][0]=objects;
        objects1[0][1]=objects2;
       resp.getWriter().write(gson.toJson(objects1));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
